home *** CD-ROM | disk | FTP | other *** search
- // Tools Plus Tutorial -- Picture Buttons
-
-
-
-
- #include "ToolsPlus.h"
-
-
- // Picture button constants to make code more readable…
- #define LeftAlignButton 3
- #define CenterAlignButton 4
- #define RightAlignButton 5
- #define JustifyButton 6
- #define CutButton 7
- #define BucketButton 8
- #define ClipboardButton 9
- #define PrinterButton 12
- #define ModemButton 13
- #define ScrollingButton 15
- #define PowerButton 23
- #define DoneButton 25
-
- // Picture button icon constants to make code more readable…
- #define PrinterIcon 150
- #define ModemIcon 151
- #define LeftAlignIcon 408
- #define CenterAlignIcon 409
- #define RightAlignIcon 410
- #define JustifyIcon 411
- #define CutIcon 412
- #define BucketIcon 413
- #define ClipboardIcon 414
- #define PowerIcon 450
- #define ScrollingIcon 458
- #define DoneIcon 464
-
-
-
-
- TPPollRecord Poll; // Polling record to retrieve event information
- Boolean ExitTheDemo; // Should the demo terminate?
-
- short theButton; // Button counter
-
-
- void ApplicationInitialization (void);
-
-
-
-
-
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- void main(void)
- {
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(0L);
- MaxApplZone();
-
-
- if (!InitToolsPlus(1, 2, UseColor))
- ExitToShell();
-
- ApplicationInitialization();
-
- while (!ExitTheDemo) //Main Event Loop
- {
- if (PollSystem(&Poll)) //If an event is available, process the event…
- {
- switch (Poll.What)
- {
- case doPictButton:
- switch (Poll.Button.Num)
- {
- case LeftAlignButton: case CenterAlignButton:
- case RightAlignButton: case JustifyButton:
- // Cycle through the group and turn off the buttons
- // that weren't clicked (deselect them)…
- for (theButton = LeftAlignButton; theButton <= JustifyButton; theButton++)
- SelectPictButton(theButton, theButton == Poll.Button.Num);
- break;
-
- case PrinterButton: case ModemButton:
- // Cycle through the group and turn off the buttons
- // that weren't clicked (deselect them)…
- for (theButton = PrinterButton; theButton <= ModemButton; theButton++)
- SelectPictButton(theButton, theButton == Poll.Button.Num);
- break;
-
- case DoneButton:
- ExitTheDemo = true;
- break;
-
- default: // Ignore all other buttons…
- break;
- }
- break;
-
- case doMenu: // The only menu item available is "Quit"…
- ExitTheDemo = true;
- break;
-
- case doChgWindow: // Activate the clicked window…
- ActivateWindow(Poll.Window);
- break;
-
- default:
- break; //All other events are ignored
- }
- }
- }
- }
-
-
-
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- void ApplicationInitialization (void)
- {
- // Do all the application setup before you start polling for events…
-
- #define DemoWindow1 1
- #define DemoWindow2 2
-
- // This big 3D button stays down when selected, lightens when selected,
- // and gets whited out when disabled…
- #define Big3Dspec picbutLockSelected + picbutBigSICN3D + picbutSelectLightenSICN3D + picbutDimUsingWhite
-
- // This small 3D button pops back up after being selected, lightens wheN
- // selected, and gets whited out when disabled…
- #define Small3Dspec picbutSelectLightenSICN3D + picbutDimUsingWhite
-
- // This ordinary icon (printer and modem) is selected when the mouse-down occurs,
- // stays down when selected, darkens when selected. When disabled, a white
- // screen effect is used and the border is preserved…
- #define OrdinaryIconSpec picbutInstantEvent + picbutLockSelected + picbutSelectDarken + picbutDimUsingWhite + picbutDimLeaveBorder
-
-
-
- // Do all the application setup before you start polling for events…
- AppleMenu("\p");
- Menu(1, 0, enabled, "\pFile");
- Menu(1, 1, enabled, "\pQuit/Q");
- UpdateMenuBar();
-
-
- WindowOpen(DemoWindow1, 0, 0, 215, 160, "\pDummy Window", noGrowDocProc + wCenter, NoGoAway, NotModal);
- WindowOpen(DemoWindow2, 0, 0, 215, 160, "\pPicture Buttons", noGrowDocProc + wTile, NoGoAway, NotModal);
-
- NewPictButton(LeftAlignButton, 12, 8, LeftAlignIcon, Big3Dspec, enabled, notSelected, 0, 0, 0);
- NewPictButton(CenterAlignButton, 35, 8, CenterAlignIcon, Big3Dspec, enabled, notSelected, 0, 0, 0);
- NewPictButton(RightAlignButton, 58, 8, RightAlignIcon, Big3Dspec, enabled, notSelected, 0, 0, 0);
- NewPictButton(JustifyButton, 81, 8, JustifyIcon, Big3Dspec, enabled, notSelected, 0, 0, 0);
-
- NewPictButton(CutButton, 128, 9, CutIcon, Small3Dspec, enabled, notSelected, 0, 0, 0);
- NewPictButton(BucketButton, 151, 9, BucketIcon, Small3Dspec, enabled, notSelected, 0, 0, 0);
- NewPictButton(ClipboardButton, 174, 9, ClipboardIcon, Small3Dspec, enabled, notSelected, 0, 0, 0);
-
- NewPictButton(PrinterButton, 22, 50, PrinterIcon, OrdinaryIconSpec, enabled, selected, 0, 0, 0);
- NewPictButton(ModemButton, 63, 50, ModemIcon, OrdinaryIconSpec, enabled, notSelected, 0, 0, 0);
-
- // This is a dual state button (Power-On, Power-Off), so it is considered to be a
- // "Multi-Stage" button (Off=0, 1=On). The button's value changes automatically
- // when selected by the user. The values "wrap" to allow 1 (on) to start back
- // at 0 (off) again. An alternate icon is used to depict the selected button
- // (down position), and disabled button for maximum visual control…
- NewPictButton(PowerButton, 131, 50, PowerIcon, picbutMultiStage + picbutAutoValueChg + picbutValueWrap + picbutSelectAltImage + picbutDimAltImage, enabled, notSelected, 0, 0, 1);
-
- // This scrolling button has nine icon images in its SICN resource. It keeps
- // producing doPictButton events while the mouse is held down. The button's
- // value changes automatically with the top 1/2 of the button incrementing the
- // value and the bottom 1/2 decrementing it. This is a BIG 3D button that looks
- // "pushed" when selected (not darker or ligher)…
- NewPictButton(ScrollingButton, 172, 55, ScrollingIcon, picbutRepeatEvents + picbutAutoValueChg + picbutTopBottomSplit + picbutBigSICN3D + picbutSelectPushedSICN3D, enabled, notSelected, 1, 5, 9);
-
- // This is a really simple push-button that uses an alternate icon when the
- // button is selected. When disabled, a white screen is overlayed and the
- // border is preserved…
- NewPictButton(DoneButton, 131, 130, DoneIcon, picbutSelectAltImage + picbutDimUsingWhite + picbutDimLeaveBorder, enabled, notSelected, 0, 0, 0);
-
- ExitTheDemo = false;
- }